import bus from '@/bus'
export default {
  status: 'pass',
  totalItem: 1,
  pageSize: window.$pageSize,
  currentPage: 1,
  columns: [
    {
      title: '门店ID',
      key: 'storeId',
      align: 'left',
      minWidth: 200
    },
    {
      title: '门店名称',
      key: 'storeName',
      align: 'left',
      minWidth: 250,
      render (h, p) {
        return <p class='e1' title={p.row.storeName}> { p.row.storeName }</p>
      }
    },
    {
      title: '经销商',
      key: 'distributorName',
      align: 'left',
      minWidth: 250,
      render (h, p) {
        return <p class='e1' title={p.row.distributorName}> { p.row.distributorName }</p>
      }
    },
    {
      title: '科室',
      key: 'departmentOfficeName',
      align: 'left',
      minWidth: 100
    },
    {
      title: '部门',
      key: 'departmentName',
      align: 'left',
      minWidth: 200
    },
    {
      title: '门店类型',
      key: 'storeTypeStr',
      align: 'left',
      minWidth: 100
    },
    {
      title: '联系人',
      key: 'storeOwnerName',
      align: 'left',
      minWidth: 100
    },
    {
      title: '电话',
      key: 'storeConcatPhone',
      align: 'left',
      minWidth: 150
    },
    {
      title: '门店维护人',
      key: 'salesName',
      align: 'left',
      minWidth: 120
    },
    {
      title: '经营主品牌',
      key: 'brandName',
      align: 'left',
      minWidth: 120
    },
    {
      title: '是否4-5新店',
      key: 'isNewStore',
      align: 'left',
      minWidth: 120,
      render: (h, p) => {
        return <div>{p.row.isNewStore ? '是' : '否'}</div>
      }
    },
    {
      title: '门店4-5月任务完成/指标',
      minWidth: 200,
      render: (h, p) => {
        if (!p.row.taskDTOList || !p.row.taskDTOList.length) return <div>-</div>
        const taskDTOList = p.row.taskDTOList
        const completedStr = p.row.isNewStore
          ? taskDTOList[0].completedStr
          : taskDTOList.reduce((acc, cur) => acc + cur.completed, 0)
        const targetStr = p.row.isNewStore
          ? taskDTOList[0].targetStr
          : taskDTOList.reduce((acc, cur) => acc + cur.target, 0)
        return <div class='link' onClick={() => bus.$emit('onViewGoodsDetail', { id: p.row.storeId, type: 2 })}>{ `${completedStr} / ${targetStr}` }</div>
      }
    },
    {
      title: '16寸及以上（规定花纹）入库情况',
      key: 'sizeTaskComplete',
      minWidth: 250,
      render: (h, p) => {
        return h(
          'div',
          {
            class: 'link',
            on: {
              click: () => {
                bus.$emit('onViewGoodsDetail', { id: p.row.storeId, type: 1 })
              }
            }
          },
          p.row.sizeTaskComplete
        )
      }
    },
    {
      title: '4月任务完成/指标',
      minWidth: 180,
      align: 'right',
      render: (h, p) => {
        if (!p.row.taskDTOList || !p.row.taskDTOList.length) return <div>-</div>
        const taskDTOList = p.row.taskDTOList
        const textTemplate = p.row.isNewStore
          ? <div>-</div>
          : <div class='link'
            onClick={() => bus.$emit('onViewGoodsDetail', { id: p.row.storeId, type: 2, month: 4, year: 2021 })}>
            {`${taskDTOList[0].completedStr} / ${taskDTOList[0].targetStr}`}
          </div>
        return textTemplate
      }
    },
    {
      title: '5月任务完成/指标',
      minWidth: 180,
      align: 'right',
      render: (h, p) => {
        if (!p.row.taskDTOList || !p.row.taskDTOList.length) return <div>-</div>
        const taskDTOList = p.row.taskDTOList
        const textTemplate = p.row.isNewStore
          ? <div>-</div>
          : <div class='link'
            onClick={() => bus.$emit('onViewGoodsDetail', { id: p.row.storeId, type: 2, month: 5, year: 2021 })}>
            {`${taskDTOList[1].completedStr} / ${taskDTOList[1].targetStr}`}
          </div>
        return textTemplate
      }
    },
    {
      title: '礼品兑换1',
      key: 'firstGiftName',
      minWidth: 150
    },
    {
      title: '收货地址(兑换1)',
      minWidth: 200,
      render: (h, p) => {
        const {
          firstProvinceName, firstCityName, firstAreaName, firstStreet, firstAddress
        } = p.row
        return <div>{(firstProvinceName || '') + (firstCityName || '') + (firstAreaName || '') + (firstStreet || '') + (firstAddress || '')}</div>
      }
    },
    {
      title: '兑换后条数(兑换1)',
      key: 'firstExchangeEndScore',
      minWidth: 160
    },
    {
      title: '礼品兑换2',
      key: 'secondGiftName',
      minWidth: 150
    },
    {
      title: '收货地址(兑换2)',
      minWidth: 200,
      render: (h, p) => {
        const {
          secondProvinceName, secondCityName, secondAreaName, secondStreet, secondAddress
        } = p.row
        return <div>{(secondProvinceName || '') + (secondCityName || '') + (secondAreaName || '') + (secondStreet || '') + (secondAddress || '')}</div>
      }
    },
    {
      title: '兑换后条数(兑换2)',
      key: 'secondExchangeEndScore',
      minWidth: 160
    },
    {
      title: '快递单号',
      minWidth: 250,
      render: (h, p) => {
        const arr = []
        const temp = p.row.trackingNumber ? p.row.trackingNumber.split(',') : []
        temp.forEach(item => {
          const target = h(
            'div',
            {
              class: 'link',
              on: {
                click: () => { bus.$emit('express', item) }
              }
            },
            item
          )
          arr.push(target)
        })
        return h('div', arr)
      }
    }
  ],
  data: []
}
